package com.jxx.controller;

import com.jxx.pojo.Item;
import com.jxx.pojo.ItemDesc;
import com.jxx.service.ItemService;
import com.jxx.util.ObjectMapperUtil;
import com.jxx.vo.EasyUITable;
import com.jxx.vo.ItemDetails;
import com.jxx.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/item/")
public class ItemController {
    @Autowired
    private ItemService itemService;

    /**
     * @author Zcc
     * @desc 商品分页
     * @param   page,rows
     * @return EasyUITable
     * @date 2020年11月27日08:26:51
     */
    @RequestMapping("findItemByPage")
    public EasyUITable findItemByPage(Integer page, Integer rows,Integer categoryId,String msg){
        return itemService.findItemByPage(page,rows,categoryId,msg);
    }

    @RequestMapping("addItem")
    public SysResult addItem(@RequestBody List<Object> itemList){
        String itemJSON = ObjectMapperUtil.toJSON(itemList.get(0));
        String itemDescJSON = ObjectMapperUtil.toJSON(itemList.get(1));
        Item item = ObjectMapperUtil.toObject(itemJSON, Item.class);
        ItemDesc itemDesc = ObjectMapperUtil.toObject(itemDescJSON, ItemDesc.class);
        return itemService.addItem(item,itemDesc);
    }

    @RequestMapping("findItem")
    public ItemDetails findItem(Integer itemId){
        return itemService.findItem(itemId);
    }

}
